<script setup lang="ts">
import { shallowRef, onMounted, ref, reactive } from 'vue';
import { useRouter } from 'vue-router';
import { SignUtil } from '@util/signin';
import CopyRight from '@components/copyright.vue';
//中文包
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';
const locale = zhCn;
const router = useRouter();
//当前路由名称
const currentRoute = reactive({ currentRoute: 'signin' });
//定义更新路由函数
const changeRoute = (name, query, hideParam = false) => {
	if (!query) {
		query = {};
	}
	if (!hideParam) {
		router.push({ name: name, query: query, replace: true });
	} else {
		//利用history保存参数，使得参数不在浏览器上出现
		router.push({ name: name, state: query, replace: true });
	}
	//同步修改菜单选中项
	//Main_Header.value?.switchMenu(name);
	currentRoute['currentRoute'] = name;
};
//关闭浏览器后再打开，要先清除缓存
onMounted(() => {
	let _t = performance.navigation.type;
	//console.log("performance.navigation.type : "+_t);
	if (_t == 0) {
		//首次加载
		SignUtil.clearUser();
	}
	//判断是刷新还是关闭浏览器
	let beginTime = 0; //开始时间
	let differTime = 0; //时间差
	window.onunload = function() {
		differTime = new Date().getTime() - beginTime;
		if (differTime <= 5) {
			//console.log('这是关闭');
			SignUtil.clearUser();
		} else {
			//console.log('这是刷新');
		}
	};
	window.onbeforeunload = function() {
		beginTime = new Date().getTime();
	};
});

</script>

<template>
		<el-config-provider :locale="locale">
			<el-container :style="{ height: '90vh' }">
				<el-main :style="{ overflow: 'hidden' }">
					<!-- 配置路由出口 -->
					<router-view :routeName="currentRoute['currentRoute']" @onChangeRoute="changeRoute" />
				</el-main>
			<el-footer class="curFoot"><CopyRight></CopyRight></el-footer>
			</el-container>
		</el-config-provider>
</template>

<style scoped>
</style>
